package com.pajk.user.service.common.idpool;

import com.pajk.idgen.IDGenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Mock implementation of IDGenService
 * for test convenience
 *
 * @author Haomin Liu
 */

public class MockIDGenerator implements IDGenService {
    private final static Logger Log = LoggerFactory.getLogger(MockIDGenerator.class);
    private Long idGenerator = 0L;

    @Override
    public synchronized String getNextId(String s, String s2, int i) {
        List<Long> Ids = new ArrayList<Long>();
        for(int j = 0; j < i; j++){
            while (((idGenerator / 10) % 10 != 0) ||
                    ((idGenerator / 1000) % 10 != 0)){
                idGenerator += 1;
            }
            Ids.add(idGenerator);
            idGenerator += 1;
        }

        StringBuilder sb = new StringBuilder();
        for(Long id : Ids){
            sb.append(id).append(',');
        }
        String out = sb.substring(0, sb.length()-1);
        Log.debug("generated {} ids, raw string: {}", i, out);
        return out;
    }
}
